package vn.com.servicedirectory.service.impl;

import javax.inject.Inject;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import vn.com.servicedirectory.model.Programme;
import vn.com.servicedirectory.repository.ProgrammeRepository;
import vn.com.servicedirectory.service.ProgrammeService;

@Service
public class ProgrammeServiceImpl implements ProgrammeService {
	@Inject
	protected ProgrammeRepository programmeRepository;
	
	@Override
	@Transactional(readOnly=true)
	public Page<Programme> findByName(String name, int page, int size,
			boolean active) {
		Pageable pageable=new PageRequest(page, size, new Sort(Direction.ASC,"name"));
		Page<Programme> programmePage;
		if("all".equals(name)){
			//find all
			programmePage=programmeRepository.findByActive(active, pageable);
		}else{
			//find each 
			programmePage=programmeRepository.findByName(name.charAt(0), name.charAt(1), active, pageable);
		}
		return programmePage;
	}

	@Override
	@Transactional
	public Programme insert(Programme programme) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Programme update(Programme programme) {
		// TODO Auto-generated method stub
		return null;
	}


}